package com.ruoyi.web.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.domain.QgPayBank;
import com.ruoyi.web.service.IQgPayBankService;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * QGPay银行Controller
 *
 * @date 2023-03-15
 */
@RestController
@RequestMapping("/qg-pay/bank")
@AllArgsConstructor
public class QgPayBankController extends BaseController {
    private IQgPayBankService qgPayBankService;

    /**
     * 查询QGPay银行列表
     */
    @PreAuthorize("@ss.hasPermi('qgPay:bank:list')")
    @GetMapping("/list")
    public TableDataInfo list(QgPayBank qgPayBank) {
        startPage();
        List<QgPayBank> list = qgPayBankService.selectQgPayBankList(qgPayBank);
        return getDataTable(list);
    }

    /**
     * 导出QGPay银行列表
     */
    @PreAuthorize("@ss.hasPermi('qgPay:bank:export')")
    @Log(title = "QGPay银行", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QgPayBank qgPayBank) {
        List<QgPayBank> list = qgPayBankService.selectQgPayBankList(qgPayBank);
        ExcelUtil<QgPayBank> util = new ExcelUtil<QgPayBank>(QgPayBank.class);
        util.exportExcel(response, list, "QGPay银行数据");
    }

    /**
     * 获取QGPay银行详细信息
     */
    @PreAuthorize("@ss.hasPermi('qgPay:bank:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(qgPayBankService.selectQgPayBankById(id));
    }

    /**
     * 新增QGPay银行
     */
    @PreAuthorize("@ss.hasPermi('qgPay:bank:add')")
    @Log(title = "QGPay银行", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QgPayBank qgPayBank) {
        return toAjax(qgPayBankService.insertQgPayBank(qgPayBank));
    }

    /**
     * 修改QGPay银行
     */
    @PreAuthorize("@ss.hasPermi('qgPay:bank:edit')")
    @Log(title = "QGPay银行", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QgPayBank qgPayBank) {
        return toAjax(qgPayBankService.updateQgPayBank(qgPayBank));
    }

    /**
     * 删除QGPay银行
     */
    @PreAuthorize("@ss.hasPermi('qgPay:bank:remove')")
    @Log(title = "QGPay银行", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(qgPayBankService.deleteQgPayBankByIds(ids));
    }

    /**
     * 选项
     *
     * @param condition 查询条件
     * @return {@link TableDataInfo}
     * @since 2023/3/16 21:50
     */
    @GetMapping("/option")
    public TableDataInfo option(QgPayBank condition) {
        List<QgPayBank> list = qgPayBankService.optionList(condition);
        return getDataTable(list);
    }

    /**
     * h5查询集合
     *
     * @param condition 查询条件
     * @return {@link TableDataInfo}
     * @since 2023/3/16 21:50
     */
    @GetMapping("/app/page")
    public TableDataInfo appList(QgPayBank condition) {
        startPage();
        List<QgPayBank> list = qgPayBankService.optionList(condition);
        return getDataTable(list);
    }
}
